<%--
  Created by IntelliJ IDEA.
  User: wwh
  Date: 2017/8/9
  Time: 11:07
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<div class="admin-main">
    <div id="college">
        <fieldset class="layui-elem-field">
            <legend>创建专业</legend>
            <div class="layui-field-box">
                <form class="layui-form">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">系部：</label>
                            <div class="layui-input-inline">
                                <select name="departmentid" lay-verify="chooseDepartment" id="showDepartment"
                                        lay-search>
                                    <option value="">请选择系部</option>
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item" style="width: 300px">
                        <label class="layui-form-label">账号</label>
                        <div class="layui-input-block">
                            <input type="text" name="username" required lay-verify="required" placeholder="请输入账号"
                                   class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item" style="width: 300px">
                        <label class="layui-form-label">密码</label>
                        <div class="layui-input-block">
                            <input type="password" name="password" required lay-verify="required" placeholder="请输入密码"
                                   class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item" style="width: 300px">
                        <label class="layui-form-label">重复密码</label>
                        <div class="layui-input-block">
                            <input type="password" name="repassword" required lay-verify="repassword" placeholder="请输入密码"
                                   class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button class="layui-btn" lay-submit lay-filter="create">创建</button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>
    </div>
</div>

<script>
    "use strict";
    layui.use(['form', 'layer'], function () {
        var form = layui.form(),
            $ = layui.jquery,
            layer = layui.layer;

        axios.get('/department/findBath/' + schoolAdmin.schoolid)
            .then(function (res) {
                console.log(res);
                var array = res.data.data;
                var html = '';
                for (var i in array) {
                    html += '<option value=' + array[i].id + '>' + array[i].name + '</option>';
                }
                $('#showDepartment').append(html);
                form.render('select');
            })
            .catch(function (res) {
                console.log(res);
            });

        form.verify({
            repassword:function (value) {
                var password = $("form input[name=password]").val();
                if(password != value){
                    return "前后密码不一致";
                }
            }
        });
    });
</script>